#博客首页测试用例
from time import sleep

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

from common.Untils import BlogDriver


class BlogList:
    url = ""
    driver = ""
    def __init__(self):
        self.url="http://8.137.19.140:9090/blog_list.html"
        self.driver=BlogDriver.driver
        self.driver.get(self.url)
    #测试首页（登录情况下）
    def ListTestByLogin(self):
        #测试博客标题是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.title")
        #WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "body > div.container > div.right > div:nth-child(1) > div.title")))

        #测试博客内容是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.desc")
        #WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "body > div.container > div.right > div:nth-child(1) > div.desc")))

        #测试博客按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > a")
        #WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "body > div.container > div.right > div:nth-child(1) > a")))

        #个人信息检查昵称是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > h3")
        #WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "body > div.container > div.left > div > h3")))

        #个人信息检查头像是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > img")

        #个人信息检查“文章”是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > div:nth-child(4) > span:nth-child(1)")

        #个人信息检查“分类”是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > div:nth-child(4) > span:nth-child(2)")

        # 个人信息检查“GitHub地址”是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > a")

        # 验证点击“GitHub地址”是否成功跳转
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > a").click()
        self.driver.find_element(By.CSS_SELECTOR,"#git-header-nav > div > div > div.item.gitosc-logo > a > img.ui.inline.image.light-mode-img")
        sleep(1)
        self.driver.back()
        sleep(2)
    # 测试首页（未登录情况下）
    def ListTestByNotLogin(self):
        #点击注销
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(6)").click()
        self.driver.get("http://8.137.19.140:9090/blog_list.html")

        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangsan")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")

        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        #检查是否登录了
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > h3")

        #添加屏幕截图
        #BlogDriver.getScreenShot()

